package com.superbytecode.cloud.web.swagger;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * All rights Reserved, Designed By www.super-master.com
 *
 * @ProjectName: beacon-cloud
 * @Package: com.superbytecode.cloud.web.swagger
 * @ClassName: SwaggerConfiguration
 * @Description: [Swagger配置]
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2024/10/22 12:01
 * @Version: V1.0
 * @Copyright: 2024 www.super-master.com Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Slf4j
@Configuration
@EnableOpenApi
public class SwaggerConfiguration {
    @Value("${spring.application.name}")
    private String applicationName;
    @Value("${spring.application.version}")
    private String applicationVersion;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)//
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title(applicationName).version(applicationVersion)//
                .description(applicationName + " 接口文档")//
                .contact(new Contact(applicationName, applicationVersion, ""))//
                .build();
    }

    @Bean
    public PropertyBuilderPlugin propertyBuilderPlugin() {
        return new PropertyBuilderPlugin();
    }

    @Bean
    public PropertyBuilderValidatePlugin propertyBuilderValidatePlugin() {
        return new PropertyBuilderValidatePlugin();
    }

    @Bean
    public SwaggerConsole swaggerConsole() {
        return new SwaggerConsole();
    }

}